package com.wzx.web;

import com.wzx.bean.Contact;
import com.wzx.service.ContactService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/list")
public class ContactListServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1:创建业务对象
        ContactService contactService = new ContactService();
        //2:调用queryAll
        List<Contact> list =  contactService.queryAll();
        //3:遍历
        //1:带数据到页面  转发
        //2：更新地址  重定向
         /*  for(Contact contact:list){
            System.out.println(contact);
        }*/
        request.setAttribute("list",list);
        //请求转发
        request.getRequestDispatcher("/list.jsp").forward(request,response);
    }
}
